package com.sxzbxc.weixin.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.sxzbxc.weixin.dao.SysUserDao;
import com.sxzbxc.weixin.entity.SysUser;
import com.sxzbxc.weixin.service.SysUserServiceI;
import com.sxzbxc.weixin.util.PasswordUtil;

@Service("sysUserServiceImpl")
public class SysUserServiceImpl implements SysUserServiceI {

	
	@Autowired
	private SysUserDao userDao ;
	
	
	public SysUser checkLogin(String userName,String password) {
		SysUser user = userDao.selectByAccountNumber(userName);
        if (user != null ) {
        	try {
        		String password2 = user.getPassword();
				String decrypt = PasswordUtil.decrypt(password2, PasswordUtil.password, PasswordUtil.getSalt());
				if(password.equals(decrypt)){
					 return user;
				}
			} catch (Exception e) {
				throw new NullPointerException("姓名的格式不正确");
			}
        }
		return null;
	}


	@Override
	public List<SysUser> loadAll() {
		List<SysUser> loadAll = userDao.loadAll();
		return loadAll;
	}

	@Override
	public void insertSelective(SysUser entity) {
		userDao.insertSelective(entity);
	}

	@Override
	public SysUser selectByPrimaryKey(String id) {
		SysUser SysUser = userDao.selectByPrimaryKey(id);
		if(SysUser!=null){
			return SysUser;
		}
		return null;
	}

	@Override
	public void updateByPrimaryKeySelective(SysUser record) {
		userDao.updateByPrimaryKeySelective(record);
	}


	@Override
	public void deleteByPrimaryKey(String id) {
		userDao.deleteByPrimaryKey(id);
	}

}
